package cn.gson.work.controller;

import cn.gson.work.model.pojos.Tfiles;
import cn.gson.work.model.service.TfilesService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
public class TfilesController {
    @Autowired
    TfilesService tfs;

    /**
     * 分页条件模糊查询
     * @param page
     * @param size
     * @param fid
     * @param fname
     * @param fsecurity
     * @param fborrower
     * @return
     */
    @RequestMapping("/findTfiles")
    @ResponseBody
    public Map<String, Object> findTfiles(@RequestParam("page") Integer page,
                                          @RequestParam("size") Integer size,
                                          @RequestParam("fid") String fid,
                                          @RequestParam("fname") String fname,
                                          @RequestParam("fsecurity") String fsecurity,
                                          @RequestParam("fborrower") String fborrower){
        Page<Object> obj= PageHelper.startPage(page, size);
        tfs.findTfiles(fid,fname,fsecurity,fborrower);
        Map<String,Object> map =new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",obj.getResult());
        return map;
    }

    /**
     * 添加文件
     * @param tfiles
     */
    @RequestMapping("/addTfiles")
    @ResponseBody
    public void addTfiles(@RequestBody Tfiles tfiles){
        System.out.println(tfiles.toString());
        tfs.addTfiles(tfiles);
    }

    /**
     * 修改文件数据
     * @param tfiles
     */
    @RequestMapping("/editTfiles")
    @ResponseBody
    public void editTfiles(@RequestBody Tfiles tfiles){
        tfs.editTfiles(tfiles);
    }

    /**
     * 文件销毁
     * @param id
     */
    @RequestMapping("/delTfiles")
    @ResponseBody
    public void delTfiles(@RequestParam("id") int id){
        tfs.delTfiles(id);
    }
}
